layui.use(['layer','upload','layedit','treeSelect','table','form','laytpl','element'], function(){
    var $ = layui.$
        ,layer = layui.layer
        ,admin = layui.admin
        ,table = layui.table
        ,element = layui.element
        ,form = layui.form
        ,laytpl = layui.laytpl;
    var delFlag = null;
    var treeSelect= layui.treeSelect;//树形下拉框
    var upload = layui.upload;
    var layedit = layui.layedit;

    //图片上传
    upload.render({
        elem: '#uploadImg'
        ,url: '/upload/pic'
        // ,multiple: true
        ,field:"uploadFile"
        ,before: function(obj){
        }
        ,done: function(res){
            //上传完毕
            var url = res.url;
            $('#showImg').html('');
            $('#showImg').append('<img style="padding: 10px" width="30%" src="'+ url +'" class="layui-upload-img">');
            $("#qualificationCertificate").val(url);
        }
    });

    //图片上传
    upload.render({
        elem: '#uploadImg2'
        ,url: '/upload/pic'
        ,multiple: true
        ,field:"uploadFile"
        ,before: function(obj){
        }
        ,done: function(res){
            //上传完毕
            var url = res.url;
            /*$('#demo2').html('');*/
            $('#showImg2').append('<img style="padding: 10px" width="30%" src="'+ url +'" class="layui-upload-img">');
            $("#honors").val($("#honors").val() + url + ";");
        }
    });

    //创建一个编辑器
    window.editIndex = layedit.build('layedit_content',{
        height : 535,
        uploadImage : {
            url : "/layedit/upload/pic"
        }
    });

    form.verify({
        content: function(value) {
            return layedit.sync(editIndex);
        }
    });

    //用于同步编辑器内容到textarea
    layedit.sync(editIndex);

    //添加企业信息
    form.on('submit(add)', function(data){
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        //初始化数据
        $.ajax({
            url: '/company/add',
            data:data.field,
            type: 'POST',
            success: function (data) {
                if(data.code == 200) {
                    top.layer.close(index);
                    top.layer.msg("添加成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                } else {
                    top.layer.close(index);
                    top.layer.msg("添加失败！");
                }
            },
            error:function () {
                top.layer.close(index);
                top.layer.msg("添加失败！");
            }
        });
        return false;
    });

});

